# -*- coding: utf-8 -*-
import requests, json, pytest, yaml, os, allure
from Outputs.LOG import Log

LOG = Log()
log = LOG.log2()


def yamlread(filename):
    """
    读取yaml文件
    filename:yaml文件名称，不需要传文件后缀
    :return:
    """
    with allure.step(f"打开yaml文件：{filename}"):
        try:
            # 获取当前脚本所在文件夹路径
            curPath = os.path.dirname(os.path.realpath(__file__))
            # 获取yaml文件路径
            yamlPath = os.path.join(curPath, f"{filename}.yaml")

            # open方法打开直接读出来
            f = open(yamlPath, 'r', encoding='utf-8')
            cfg = f.read()  # 字符串格式的所有yaml数据

            d = yaml.load(cfg, Loader=yaml.FullLoader)  # 用load方法转字典
            return d  # 返回字典格式的yaml数据
        except Exception as e:
            log.error(e)
